from matplotlib import pyplot as plt
import numpy as np

plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False

# Constants.
Re = 1.496
Rm = 2.279
a = 2.773
b = 4

xe = np.linspace(-Re, Re, num=100)
xm = np.linspace(-Rm, Rm, num=100)
xf = np.linspace(1.14, Re, num=100)
ye = np.sqrt(Re**2 - xe**2)
ym = np.sqrt(Rm**2 - xm**2)
yf = b * np.sqrt(1 - (xf-Re+a)**2 / a**2)

plt.title('快速转移过程图')
plt.arrow(-1.5*Rm, 0, 3*Rm, 0, color='black',
          head_length=0.2, head_width=0.1)
plt.arrow(0, -1.5*Rm, 0, 3*Rm, color='black',
          head_length=0.2, head_width=0.1)
plt.axis('off')
plt.axis('equal')

plt.plot(xe, ye, color='lightskyblue', label='地球轨道')
plt.plot(xe, -ye, color='lightskyblue')
plt.plot(xm, ym, color='red', label='火星轨道')
plt.plot(xm, -ym, color='red')
plt.plot(xf, yf, color='gold', label='快速转移轨道')
plt.legend()

plt.plot(1.14, 1.96, marker='.', color='black')
plt.plot(2, 1.08, marker='.', color='black')
plt.plot(1.31, 1.41, marker='.', color='gold')
plt.plot([0, 1.14], [0, 1.96], linestyle='--', color='black')
plt.plot([0, 2], [0, 1.08], linestyle='--', color='black')
plt.arrow(2.17, 1.43, -0.57, 0.57, color='red',
          head_length=0.2, head_width=0.1)
plt.text(0.88, 2.4, '火星（相遇时，71.69°）', size=16)
plt.text(2.29, 1, '火星（发射时，33.96°）', size=16)
plt.text(-0.8, -0.4, '太阳', size=16)
plt.text(Re, -0.4, '地球', size=16)

plt.show()
